<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<script type="text/javascript">
function fn_maskPhone(obj) { 
    obj.value =  fn_PhoneNumStr(obj.value); 
} 
function fn_PhoneNumStr(str){ 
    var RegNotNum  = /[^0-9]/g; 
    var RegPhoneNum = ""; 
    var DataForm   = ""; 
    // return blank  
    var b = document.phistory;
	if (!((event.keyCode >= 48 && event.keyCode <= 57)
			|| (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8)) {
		alert('숫자만 입력해 주세요!');
		b.ph_phone.value = "";
		event.returnValue = false;
	}
    if( str == "" || str == null ) return ""; 
    // delete not number
    str = str.replace(RegNotNum,''); 
    if( str.length < 4 ) return str; 
    if( str.length > 3 && str.length < 7 ) { 
           DataForm = "$1-$2"; 
        RegPhoneNum = /([0-9]{3})([0-9]+)/; 
    } else if(str.length == 7 ) {
        DataForm = "$1-$2"; 
        RegPhoneNum = /([0-9]{3})([0-9]{4})/; 
    } else if(str.length == 8 ) {
        DataForm = "$1-$2-$3"; 
        RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
    } else if(str.length == 9 ) {
        DataForm = "$1-$2-$3"; 
        RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
    } else if(str.length == 10){ 
        if(str.substring(0,2)=="02"){
            DataForm = "$1-$2-$3"; 
            RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
        }else{
            DataForm = "$1-$2-$3"; 
            RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/;
        }
    } else if(str.length > 10){ 
        DataForm = "$1-$2-$3"; 
        RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
    } 
    if(RegPhoneNum != ''){
        while( RegPhoneNum.test(str) ) {  
            str = str.replace(RegPhoneNum, DataForm);  
        }
    }
    return str; 
} 
</script>
<table style="width: 550px" align="center">
<tr>
<td>
<fieldset id="entranceCar">
<legend><h3>차량진입</h3></legend>
<ul>
 	<li>
<spring:hasBindErrors name="command"/>
<form:errors path="command"/>
<form action="pHistoryInsert.do" method="post" id="phistory" name="phistory">
	<input type="hidden" name="p_num" value="${param.p_num }">
	
	<label for="ph_model"><spring:message code="phistory.write.form.model"/></label>
	<input type="text" name="ph_model" value="${command.ph_model }" maxlength="10" autofocus>
	<font color="red"><form:errors path="command.ph_model"/></font><br>
	</li>
	<li>
	<label for="ph_name"><spring:message code="phistory.write.form.name"/></label>
	<input type="text" name="ph_name" value="${command.ph_name }" maxlength="10">
	<font color="red"><form:errors path="command.ph_name"/></font><br>
	</li>
	<li>
	<label for="ph_plate"><spring:message code="phistory.write.form.plate"/></label>
	<input type="text" name="ph_plate" value="${command.ph_plate }" maxlength="10">
	<font color="red"><form:errors path="command.ph_plate"/></font><br>
	</li>
	<li>
	<label for="ph_phone"><spring:message code="phistory.write.form.phone"/></label>
	<input type="text" name="ph_phone" value="${command.ph_phone }" maxlength="13" onKeyDown="fn_maskPhone(this);" onKeyUp="fn_maskPhone(this);" autofocus placeholder="숫자만 입력.예) 1234123456789">
	<font color="red"><form:errors path="command.ph_phone"/></font><br>
	</li>
	<li>
	
	<input type="submit" value="<spring:message code="write.form.submit"/>" style="height: 22px;width: 120px;background-color: #CEFBC9">
	
	</li>
	</ul>
</form>
</fieldset>
</td>
</tr>
</table>